﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NetworkUtils;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using System.Text;

namespace UnitTestProject1
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            Data d = new Data("600006", 12.3f);
            string msg = Serialize(d);
            MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(msg));
            ms.Position = 0;
            BinaryFormatter formatter = new BinaryFormatter();
            Data data = (Data)formatter.Deserialize(ms);
        }

        public string Serialize(Object obj)
        {
            MemoryStream ms = new MemoryStream();
            BinaryFormatter formatter = new BinaryFormatter();
            formatter.Serialize(ms, obj);
            byte[] buffer = ms.GetBuffer();
            ms.Close();
            string objStr = Encoding.Unicode.GetString(buffer, 0, buffer.Length);
            return objStr;
        }
    }
}
